package com.allwees.bs.c.module.user.repository;

import com.allwees.bs.c.module.user.entity.UserEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;
import java.util.List;
import java.util.Set;

public interface UserRepository extends JpaRepository<UserEntity, Integer> {
    @Query(value = "select * from usr_user where id in ?1", nativeQuery = true)
    List<UserEntity> getByIds(List<Integer> ids);

    @Query(value = "select * from usr_user where email = ?1 or facebook_id = ?1 or google_id = ?1 or apple_id = ?1", nativeQuery = true)
    UserEntity findByEmailOrThirdId(String email);

    UserEntity getByUuid(String uuid);

    UserEntity findByUuid(String uuid);

    @Query("SELECT isInfluencer FROM UserEntity WHERE uuid = :uuid")
    Integer checkIsInfluencer(String uuid);

    UserEntity findByEmail(String email);

    UserEntity findByShareCode(String shareCode);

    UserEntity findByFacebookId(String id);

    UserEntity findByGoogleId(String id);

    UserEntity findByAppleId(String id);

    @Query("SELECT firstPaymentAt FROM UserEntity WHERE uuid = :uuid")
    Date hasOrder(String uuid);

    @Query("FROM UserEntity WHERE promoCode = :promoCode and isDeleted=0")
    UserEntity findByPromoCode(String promoCode);

    @Query("FROM UserEntity WHERE uuid in (:uuids) and isDeleted=0")
    List<UserEntity> getByUuids(Set<String> uuids);
}
